/*
 * @(#)Article.java, 2024/2/20 16:25
 *
 * Copyright (c) 2018-2024, 四川蜀天梦图数据科技有限公司.
 * All rights reserved.
 */
package controllers;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.IntField;
import org.apache.lucene.document.TextField;

import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * Article
 *
 * @author fantazy
 * @version 1.0, 2024年02月20日
 */
public final class Article implements Serializable
{
    private int no;

    private String title;

    private String content;

    private float score;

    public static Article cleanArticle(Path txt) throws IOException
    {
        String title = txt.getFileName().toString();
        int dotIndex = title.lastIndexOf(".");
        title = title.substring(0, dotIndex);
        System.out.println(title);

        String content = Files.lines(txt).collect(Collectors.joining()).toString();
        return new Article(NoCounter.nextNo(), title, content);
    }

    public Article(int no, String title, String content, float score)
    {
        this.no = no;
        this.title = title;
        this.content = content;
        this.score = score;
    }

    public Article(int no, String title, String content)
    {
        this.no = no;
        this.title = title;
        this.content = content;
    }

    public Article(String title, String content)
    {
        this.no = NoCounter.nextNo();
        this.title = title;
        this.content = content;
    }

    public Article()
    {
    }

    public int getNo()
    {
        return no;
    }

    public void setNo(int no)
    {
        this.no = no;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getContent()
    {
        return content;
    }

    public void setContent(String content)
    {
        this.content = content;
    }

    public float getScore()
    {
        return score;
    }

    public void setScore(float score)
    {
        this.score = score;
    }
}
